<template>
	<view class="content-img">
		<eui-nav-bar title="选择节点" color="#000" rightIcon="" />
		<view class="main-view">
			<view class="main-view-bg">
				<scroll-view scroll-y :style="{width:scrollWidth,height:scrollHeight}">
					<view class="padding-left-28 font-size-28 flex flex-direction-column background-fff"
						v-for="(item,index) in dataList" :key="index" @click="setSelBackItem(item)"
						:class="item.c_checked?'store-checked':''">
						<view class="sroll-store-list">
							<view class="flex-1"><span class="color-888">审批节点 </span>{{item.StepName}}</view>
							<view class="flex-1 margin-top-20"><span class="color-888">审批人
								</span>[{{item.UserNo}}]{{item.UserName}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script setup type="ts">
	import { onLoad,onReady } from '@dcloudio/uni-app';
	import { ref } from 'vue';
	import service from '@/common/service';
	import { useMainStore } from '@/store/modules/store';
	import { useLoginStore } from '@/store/modules/useLoginStore';
	const mainStore = useMainStore();
	const LoginStore = useLoginStore();
	const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight + 'px');
	const scrollWidth = ref((uni.getSystemInfoSync().windowWidth - 20) + 'px');
	const scrollHeight = ref((uni.getSystemInfoSync().windowHeight - uni.getSystemInfoSync().statusBarHeight - 62) + 'px');
	const dataList = ref([]);
	const reqUser = ref({});//前插后插人员信息
	const approveInfo = ref({});
	
	const setSelBackItem = e =>{
		reqUser.value = e;
		uni.showModal({
			title: '提示',
			content: '确认驳回到此节点?',
			success: function(res) {
				if (res.confirm) {
					ApproveNodeExcute(4, '');
				}
			}
		});
	}
	const GetApprovedNode = () =>{
		service.enjoyShowLoading('正在加载...');
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40审批",
		        ObjectData: approveInfo.value.AppRecvId,
		        MethodName: "GetApprovedNode",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        const ObjectData = res.data.ObjectData;
		        if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
					dataList.value = ObjectData;
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
			service.enjoyHideLoading();
		}, () => {
			service.enjoyHideLoading();
		});
	}
	const ApproveNodeExcute = (AppOperType, note) => {
		// service.enjoyShowLoading('正在处理...');
		let request = {
			url: LoginStore.EnjoyMain,
			data: {
				UniqueKey: "管易通40审批",
				ObjectData: {
					AppOperType: AppOperType,
					ReqUser:reqUser.value,
					SetpName: '',
					AppUser: '',
					AppSendUserNo: '',
					AppDeFineGuid: '',
					AppDeFineType: '',
					AppDetail: note,
					AppUserNo: mainStore.loginInfo.sUser,
					AppUserName: mainStore.loginInfo.sUserName,
					BillName: approveInfo.value.BillName,
					BillRealName: approveInfo.value.BillRealName,
					NodeId: approveInfo.value.AppNodeId,
					BillId: approveInfo.value.BillKey,
					...approveInfo.value
				},
				MethodName: "ApproveExcute",
			},
		}
		service.request(request, (res) => {
			service.enjoyHideLoading();
			if (res && res.data) {
				if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
					if (ObjectData != undefined && ObjectData !=null && ObjectData.AlterInFo != undefined &&ObjectData.AlterInFo != null && ObjectData.AlterInFo != '') {
						uni.showToast({
							icon: 'none',
							title: '审批失败:' + ObjectData
								.AlterInFo,
							mask: true,
							duration: 3500,
						});
					} else {
						console.log(123123123);
						SetCurrentPages();
						uni.navigateBack({
							delta: 1
						});
					}
				} else {
					service.enjoyShowToast(res.data.Exception.Message)
				}
			}
		}, () => {
			service.enjoyHideLoading();
			console.log('失败')
		});
	}
	const SetCurrentPages = () =>{
		try {
			console.log(11111);
			let pages4 = getCurrentPages();
			let prevPage4 = pages4[pages4.length - 2];
			prevPage4.$vm.$.exposed.onRefresh();
			console.log(22222);
		} catch (e) {
		}
	}
	onLoad(e=>{
		if(e.item){
			approveInfo.value = JSON.parse(e.item);
		}
		GetApprovedNode();
	})
</script>

<style lang="scss" scoped>
	@import '@/main.scss';

	.content-img {
		background-color: #FFFFFF;
		background-repeat: no-repeat;
		width: 100%;
	}

	.flex {
		display: flex;
	}

	.flex-1 {
		flex: 1;
	}

	.justify-content-space-between {
		justify-content: space-between !important;
	}

	.main-view {
		flex: 1;
		flex-direction: column;
		padding: 20rpx;
		background-color: #f2f2f2;
	}

	.main-view-bg {
		// background-color: #fff;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.background-fff {
		background-color: #fff;
	}

	.background-fff:first-child {
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
	}

	.background-fff:last-child {
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
	}

	.background-fff:last-child .sroll-store-list {
		border-bottom: none;
	}

	.padding-left-28 {
		padding-left: 28rpx;
	}

	.font-size-28 {
		font-size: 28rpx;
	}

	.flex-direction-column {
		flex-direction: column !important;
	}

	.store-checked {
		background-color: rgba(249, 250, 252, 1) !important;
	}

	.sroll-store-list {
		padding: 20rpx 28rpx 20rpx 0;
		border-bottom: solid 1px rgba(238, 238, 238, 1);
		line-height: 1;
	}

	.color-888 {
		color: rgba(136, 136, 136, 1);
	}

	.margin-top-20 {
		margin-top: 20rpx;
	}
</style>